// 比较两个对象大小

#include <iostream>
using namespace std;

enum class Suit { diamond, club, heart, spade, };

enum class Rank {
    two = 2,
    three, four, five, six, seven, eight, nine, ten,
    jack, queen, king, ace,
};

class Card {
private:
    Suit suit;
    Rank rank;

public:
    Card();
    void SetSuit(Suit suit) { this->suit = suit; }
    void SetRank(Rank rank) { this->rank = rank; }
    void ShowCard();
    bool operator>(Card rhs) {
        return rank > rhs.rank
            || (rank == rhs.rank && suit > rhs.suit);
    }
};

int main() {
    Card first, second;

    first.SetRank(Rank::ace);
    first.SetSuit(Suit::club);

    second.SetRank(Rank::ace);
    second.SetSuit(Suit::heart);

    cout << "第1张牌是";
    first.ShowCard();
    cout << "\n";

    cout << "第2张牌是";
    second.ShowCard();
    cout << "\n";

    if (first > second) {
        cout << "第1张牌比第2张牌大\n";
    }
    else {
        cout << "第1张牌不比第2张牌大\n";
    }

    first.SetRank(Rank::ace);
    first.SetSuit(Suit::club);

    second.SetRank(Rank::king);
    second.SetSuit(Suit::spade);

    cout << "第1张牌是";
    first.ShowCard();
    cout << "\n";

    cout << "第2张牌是";
    second.ShowCard();
    cout << "\n";

    if (first > second) {
        cout << "第1张牌比第2张牌大\n";
    }
    else {
        cout << "第1张牌不比第2张牌大\n";
    }

    cout << "操作符重载时不时很好!\n";
}

Card::Card() {
    cout << "构造函数\n";
    suit = Suit::club;
    rank = Rank::two;
}

void Card::ShowCard() {
    switch (suit) {
        case Suit::spade:
            cout << " ♠";
            break;
        case Suit::heart:
            cout << " ♥";
            break;
        case Suit::diamond:
            cout << " ♦";
            break;
        case Suit::club:
            cout << " ♣";
            break;
    }
    if (int(rank) < 11) {
        cout << int(rank);
    }
    else if (rank == Rank::jack) {
        cout << "J";
    }
    else if (rank == Rank::queen) {
        cout << "Q";
    }
    else if (rank == Rank::king) {
        cout << "K";
    }
    else {
        cout << "A";
    }
}